public class Test4 {
    //5.递归求解汉诺塔问题
    public static void main(String[] args) {
            int count = hanoi(3,'A','B','C');
        System.out.println(count);
    }
    public static int hanoi(int n, char pos1, char pos2, char pos3) {
        if(n == 1) {
            move(pos1,pos3);
            return n;
        }
        hanoi(n-1,pos1,pos3,pos2);
        move(pos1,pos3);
        hanoi(n-1,pos2,pos1,pos3);
        return n;
    }

    public static void move(char pos1,char pos2) {
        System.out.print(pos1+ "-> "+pos2+" ");
    }

    public static int count = 0;
    //4.写一个递归方法，输入一个非负整数，返回组成它的数字之和
    public static void main4(String[] args) {
          int b = sumeveryone(1729);
        System.out.println(b);

    }
    public static int sumeveryone(int a){
        if (a < 10){
            return a;
        }
        return a%10 + sumeveryone(a/10);
    }


    //3.按顺序打印一个数字的每一位(例如 1234 打印出 1 2 3 4)    （递归）
    public static void main3(String[] args) {
          int a = 1234;
        System.out.println(a);
    }
    public static void print(double n) {
        if(n < 10) {
            System.out.print(n);
            return;
        }
        print(n/10);
        System.out.println(n%10);
    }
    //2.递归求 1 + 2 + 3 + ... + 10
    public static void main2(String[] args) {
            int a = sum(10);
        System.out.println(a);
    }
    public  static int sum(int x){
       if (x == 1){
           return 1;
       }
       int fac = x + sum(x -1);
       return fac;
    }
    //1.递归求 N 的阶乘
    public static int fac(int n) {
        if(n == 1) {
            return 1;
        }
        return n * fac(n-1);
    }
    public static void main1(String[] args) {
        int a = 3;
         int ret = fac(a);
        System.out.println(ret);
    }
}

